<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>SA实战 ·《SpringCloud Alibaba实战》第19章-消息服务：项目整合RocketMQ | 冰河技术</title>
    <meta name="generator" content="VuePress 1.9.7">
    <link rel="icon" href="/favicon.ico">
    <script charset="utf-8" async="async" src="/js/jquery.min.js"></script>
    <script charset="utf-8" async="async" src="/js/global.js"></script>
    <script charset="utf-8" async="async" src="/js/fingerprint2.min.js"></script>
    <script charset="utf-8" async="async" src="https://v1.cnzz.com/z_stat.php?id=1281063564&amp;web_id=1281063564"></script>
    <script charset="utf-8" async="async" src="https://s9.cnzz.com/z_stat.php?id=1281064551&amp;web_id=1281064551"></script>
    <script>
            var _hmt = _hmt || [];
            (function() {
              var hm = document.createElement("script");
              hm.src = "https://hm.baidu.com/hm.js?d091d2fd0231588b1d0f9231e24e3f5e";
              var s = document.getElementsByTagName("script")[0];
              s.parentNode.insertBefore(hm, s);
            })();
            </script>
    <meta name="description" content="包含：编程语言，开发技术，分布式，微服务，高并发，高可用，高可扩展，高可维护，JVM技术，MySQL，分布式数据库，分布式事务，云原生，大数据，云计算，渗透技术，各种面试题，面试技巧...">
    <meta property="article:modified_time" content="2022-05-23T11:30:51.000Z">
    <meta property="og:title" content="SA实战 ·《SpringCloud Alibaba实战》第19章-消息服务：项目整合RocketMQ">
    <meta property="og:type" content="article">
    <meta property="og:url" content="/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html">
    <meta name="twitter:title" content="SA实战 ·《SpringCloud Alibaba实战》第19章-消息服务：项目整合RocketMQ">
    <meta name="twitter:url" content="/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html">
    <meta name="twitter:card" content="summary_large_image">
    <meta name="robots" content="all">
    <meta name="author" content="冰河">
    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Expires" content="0">
    <meta name="keywords" content="冰河，冰河技术, 编程语言，开发技术，分布式，微服务，高并发，高可用，高可扩展，高可维护，JVM技术，MySQL，分布式数据库，分布式事务，云原生，大数据，云计算，渗透技术，各种面试题，面试技巧">
    <meta name="apple-mobile-web-app-capable" content="yes">
    
    <link rel="preload" href="/assets/css/0.styles.ab888ebb.css" as="style"><link rel="preload" href="/assets/css/styles.css?v=1653305936337" as="style"><link rel="preload" href="/assets/js/cg-styles.js?v=1653305936337" as="script"><link rel="preload" href="/assets/js/cg-app.js?v=1653305936337" as="script"><link rel="preload" href="/assets/js/cg-4.js?v=1653305936337" as="script"><link rel="preload" href="/assets/js/cg-3.js?v=1653305936337" as="script"><link rel="preload" href="/assets/js/cg-307.js?v=1653305936337" as="script"><link rel="preload" href="/assets/js/cg-5.js?v=1653305936337" as="script"><link rel="preload" href="/assets/js/cg-6.js?v=1653305936337" as="script">
    <link rel="stylesheet" href="/assets/css/0.styles.ab888ebb.css"><link rel="stylesheet" href="/assets/css/styles.css?v=1653305936337">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><!----> <span class="site-name">冰河技术</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/md/other/guide-to-reading.html" class="nav-link">
  导读
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="核心技术" class="dropdown-title"><span class="title">核心技术</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          Java核心技术
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/core/java/basics/2022-04-28-全网最全正则表达式总结.html" class="nav-link">
  Java基础
</a></li><li class="dropdown-subitem"><a href="/md/core/java/advanced/default.html" class="nav-link">
  Java进阶
</a></li><li class="dropdown-subitem"><a href="/md/core/java/senior/default.html" class="nav-link">
  Java高级
</a></li><li class="dropdown-subitem"><a href="/md/core/java/java8/2022-03-31-001-Java8有哪些新特性呢？.html" class="nav-link">
  Java8新特性
</a></li></ul></li><li class="dropdown-item"><h4>
          Spring核心技术
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/core/spring/ioc/2022-04-04-001-聊聊Spring注解驱动开发那些事儿.html" class="nav-link">
  IOC核心技术
</a></li><li class="dropdown-subitem"><a href="/md/core/spring/aop/default.html" class="nav-link">
  AOP核心技术
</a></li></ul></li><li class="dropdown-item"><h4>
          JVM核心技术
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/core/jvm/2022-04-18-001-JVM调优的几种场景.html" class="nav-link">
  JVM调优技术
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="性能调优" class="dropdown-title"><span class="title">性能调优</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/performance/jvm/default.html" class="nav-link">
  JVM性能调优
</a></li><li class="dropdown-item"><!----> <a href="/md/performance/tomcat/default.html" class="nav-link">
  Tomcat性能调优
</a></li><li class="dropdown-item"><!----> <a href="/md/performance/mysql/default.html" class="nav-link">
  MySQL性能调优
</a></li><li class="dropdown-item"><!----> <a href="/md/performance/system/default.html" class="nav-link">
  操作系统性能调优
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="并发编程" class="dropdown-title"><span class="title">并发编程</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/concurrent/bottom/default.html" class="nav-link">
  底层技术
</a></li><li class="dropdown-item"><!----> <a href="/md/concurrent/source/2020-03-30-001-一文搞懂线程与多线程.html" class="nav-link">
  源码分析
</a></li><li class="dropdown-item"><!----> <a href="/md/concurrent/basics/2020-03-30-001-明明中断了线程，却为何不起作用呢？.html" class="nav-link">
  基础案例
</a></li><li class="dropdown-item"><!----> <a href="/md/concurrent/ActualCombat/default.html" class="nav-link">
  实战案例
</a></li><li class="dropdown-item"><!----> <a href="/md/concurrent/interview/default.html" class="nav-link">
  面试
</a></li><li class="dropdown-item"><!----> <a href="/md/concurrent/framework/default.html" class="nav-link">
  系统架构
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="框架源码" class="dropdown-title"><span class="title">框架源码</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/frame/spring/default.html" class="nav-link">
  Spring源码
</a></li><li class="dropdown-item"><!----> <a href="/md/frame/springmvc/default.html" class="nav-link">
  SpringMVC源码
</a></li><li class="dropdown-item"><!----> <a href="/md/frame/mybatis/default.html" class="nav-link">
  MyBatis源码
</a></li><li class="dropdown-item"><!----> <a href="/md/frame/dubbo/default.html" class="nav-link">
  Dubbo源码
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="分布式" class="dropdown-title"><span class="title">分布式</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          缓存技术
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/cache/default.html" class="nav-link">
  Redis
</a></li></ul></li><li class="dropdown-item"><h4>
          服务注册发现
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/zookeeper/default.html" class="nav-link">
  Zookeeper
</a></li></ul></li><li class="dropdown-item"><h4>
          消息中间件
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/mq/rabbitmq/default.html" class="nav-link">
  RabbitMQ
</a></li><li class="dropdown-subitem"><a href="/md/distributed/mq/rocketmq/default.html" class="nav-link">
  RocketMQ
</a></li><li class="dropdown-subitem"><a href="/md/distributed/mq/kafka/default.html" class="nav-link">
  Kafka
</a></li></ul></li><li class="dropdown-item"><h4>
          网络通信
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/netty/default.html" class="nav-link">
  Netty
</a></li></ul></li><li class="dropdown-item"><h4>
          远程调用
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/dubbo/default.html" class="nav-link">
  Dubbo
</a></li></ul></li><li class="dropdown-item"><h4>
          数据库
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/mongodb/default.html" class="nav-link">
  MongoDB
</a></li></ul></li><li class="dropdown-item"><h4>
          搜索引擎
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/es/default.html" class="nav-link">
  ElasticSearch
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="微服务" class="dropdown-title"><span class="title">微服务</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/microservices/springboot/default.html" class="nav-link">
  SpringBoot
</a></li><li class="dropdown-item"><!----> <a href="/md/microservices/springcloudalibaba/2022-04-02-SpringCloudAlibaba专栏开篇.html" class="nav-link">
  SpringCloudAlibaba
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="中间件" class="dropdown-title"><span class="title">中间件</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/middleware/bytecode/2022-04-11-001-工作多年的你依然重复做着CRUD-是否接触过这种技术.html" class="nav-link">
  字节码编程
</a></li><li class="dropdown-item"><!----> <a href="/md/middleware/threadpool/default.html" class="nav-link">
  手写线程池
</a></li><li class="dropdown-item"><!----> <a href="/md/middleware/limiter/default.html" class="nav-link">
  分布式限流
</a></li><li class="dropdown-item"><!----> <a href="/md/middleware/independent/default.html" class="nav-link">
  开源项目
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="项目实战" class="dropdown-title"><span class="title">项目实战</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/microservices/springcloudalibaba/2022-04-02-SpringCloudAlibaba专栏开篇.html" class="nav-link">
  SpringCloud Alibaba实战
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="渗透技术" class="dropdown-title"><span class="title">渗透技术</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/hack/environment/2022-04-17-001-安装Kali系统.html" class="nav-link">
  基础环境篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/tools/2022-04-17-001-使用Easy-Creds工具攻击无线网络.html" class="nav-link">
  渗透工具篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/horse/2022-05-02-001-各种一句话木马大全.html" class="nav-link">
  木马篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/sql/2022-05-02-001-sqli-labs-master下载与安装.html" class="nav-link">
  SQL注入篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/shell/2022-05-02-001-各种解析漏洞拿shell.html" class="nav-link">
  漏洞拿Shell篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/crack/2022-05-02-001-使用rarcrack暴力破解RAR-ZIP-7Z压缩包.html" class="nav-link">
  暴力破解篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/bash/2022-05-02-001-3389脚本开启代码(vbs版).html" class="nav-link">
  渗透脚本篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/raising/2022-05-02-001-数据库提权.html" class="nav-link">
  数据与系统提权篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/client/2022-05-02-001-浏览器渗透.html" class="nav-link">
  客户端渗透篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/sociology/2022-05-02-001-Metasploit之社会工程学工具包.html" class="nav-link">
  社会工程学
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/question/2022-05-02-001-HTTP错误4031禁止访问-执行访问被拒绝.html" class="nav-link">
  问题记录篇
</a></li></ul></div></div><div class="nav-item"><a href="/md/interview/2022-04-18-001-面试必问-聊聊JVM性能调优.html" class="nav-link">
  面试必问系列
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="📚PDF" class="dropdown-title"><span class="title">📚PDF</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          出版图书
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/knowledge/book/2022-03-29-深入理解分布式事务.html" class="nav-link">
  《深入理解分布式事务：原理与实战》
</a></li><li class="dropdown-subitem"><a href="/md/knowledge/book/2022-03-29-MySQL技术大全.html" class="nav-link">
  《MySQL技术大全：开发、优化与运维实战》
</a></li><li class="dropdown-subitem"><a href="/md/knowledge/book/2022-03-29-海量数据处理与大数据技术实战.html" class="nav-link">
  《海量数据处理与大数据技术实战》
</a></li></ul></li><li class="dropdown-item"><h4>
          电子书籍
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/knowledge/pdf/2022-03-30-《冰河的渗透实战笔记》电子书，442页，37万字，正式发布.html" class="nav-link">
  冰河的渗透实战笔记
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="关于" class="dropdown-title"><span class="title">关于</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/about/me/about-me.html" class="nav-link">
  关于自己
</a></li><li class="dropdown-item"><!----> <a href="/md/about/study/default.html" class="nav-link">
  关于学习
</a></li><li class="dropdown-item"><!----> <a href="/md/about/job/default.html" class="nav-link">
  关于职场
</a></li></ul></div></div><div class="nav-item"><a href="https://space.bilibili.com/517638832" target="_blank" rel="noopener noreferrer" class="nav-link external">
  B站
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><a href="https://github.com/binghe001/BingheGuide" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Github
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/md/other/guide-to-reading.html" class="nav-link">
  导读
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="核心技术" class="dropdown-title"><span class="title">核心技术</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          Java核心技术
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/core/java/basics/2022-04-28-全网最全正则表达式总结.html" class="nav-link">
  Java基础
</a></li><li class="dropdown-subitem"><a href="/md/core/java/advanced/default.html" class="nav-link">
  Java进阶
</a></li><li class="dropdown-subitem"><a href="/md/core/java/senior/default.html" class="nav-link">
  Java高级
</a></li><li class="dropdown-subitem"><a href="/md/core/java/java8/2022-03-31-001-Java8有哪些新特性呢？.html" class="nav-link">
  Java8新特性
</a></li></ul></li><li class="dropdown-item"><h4>
          Spring核心技术
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/core/spring/ioc/2022-04-04-001-聊聊Spring注解驱动开发那些事儿.html" class="nav-link">
  IOC核心技术
</a></li><li class="dropdown-subitem"><a href="/md/core/spring/aop/default.html" class="nav-link">
  AOP核心技术
</a></li></ul></li><li class="dropdown-item"><h4>
          JVM核心技术
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/core/jvm/2022-04-18-001-JVM调优的几种场景.html" class="nav-link">
  JVM调优技术
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="性能调优" class="dropdown-title"><span class="title">性能调优</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/performance/jvm/default.html" class="nav-link">
  JVM性能调优
</a></li><li class="dropdown-item"><!----> <a href="/md/performance/tomcat/default.html" class="nav-link">
  Tomcat性能调优
</a></li><li class="dropdown-item"><!----> <a href="/md/performance/mysql/default.html" class="nav-link">
  MySQL性能调优
</a></li><li class="dropdown-item"><!----> <a href="/md/performance/system/default.html" class="nav-link">
  操作系统性能调优
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="并发编程" class="dropdown-title"><span class="title">并发编程</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/concurrent/bottom/default.html" class="nav-link">
  底层技术
</a></li><li class="dropdown-item"><!----> <a href="/md/concurrent/source/2020-03-30-001-一文搞懂线程与多线程.html" class="nav-link">
  源码分析
</a></li><li class="dropdown-item"><!----> <a href="/md/concurrent/basics/2020-03-30-001-明明中断了线程，却为何不起作用呢？.html" class="nav-link">
  基础案例
</a></li><li class="dropdown-item"><!----> <a href="/md/concurrent/ActualCombat/default.html" class="nav-link">
  实战案例
</a></li><li class="dropdown-item"><!----> <a href="/md/concurrent/interview/default.html" class="nav-link">
  面试
</a></li><li class="dropdown-item"><!----> <a href="/md/concurrent/framework/default.html" class="nav-link">
  系统架构
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="框架源码" class="dropdown-title"><span class="title">框架源码</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/frame/spring/default.html" class="nav-link">
  Spring源码
</a></li><li class="dropdown-item"><!----> <a href="/md/frame/springmvc/default.html" class="nav-link">
  SpringMVC源码
</a></li><li class="dropdown-item"><!----> <a href="/md/frame/mybatis/default.html" class="nav-link">
  MyBatis源码
</a></li><li class="dropdown-item"><!----> <a href="/md/frame/dubbo/default.html" class="nav-link">
  Dubbo源码
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="分布式" class="dropdown-title"><span class="title">分布式</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          缓存技术
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/cache/default.html" class="nav-link">
  Redis
</a></li></ul></li><li class="dropdown-item"><h4>
          服务注册发现
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/zookeeper/default.html" class="nav-link">
  Zookeeper
</a></li></ul></li><li class="dropdown-item"><h4>
          消息中间件
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/mq/rabbitmq/default.html" class="nav-link">
  RabbitMQ
</a></li><li class="dropdown-subitem"><a href="/md/distributed/mq/rocketmq/default.html" class="nav-link">
  RocketMQ
</a></li><li class="dropdown-subitem"><a href="/md/distributed/mq/kafka/default.html" class="nav-link">
  Kafka
</a></li></ul></li><li class="dropdown-item"><h4>
          网络通信
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/netty/default.html" class="nav-link">
  Netty
</a></li></ul></li><li class="dropdown-item"><h4>
          远程调用
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/dubbo/default.html" class="nav-link">
  Dubbo
</a></li></ul></li><li class="dropdown-item"><h4>
          数据库
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/mongodb/default.html" class="nav-link">
  MongoDB
</a></li></ul></li><li class="dropdown-item"><h4>
          搜索引擎
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/es/default.html" class="nav-link">
  ElasticSearch
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="微服务" class="dropdown-title"><span class="title">微服务</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/microservices/springboot/default.html" class="nav-link">
  SpringBoot
</a></li><li class="dropdown-item"><!----> <a href="/md/microservices/springcloudalibaba/2022-04-02-SpringCloudAlibaba专栏开篇.html" class="nav-link">
  SpringCloudAlibaba
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="中间件" class="dropdown-title"><span class="title">中间件</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/middleware/bytecode/2022-04-11-001-工作多年的你依然重复做着CRUD-是否接触过这种技术.html" class="nav-link">
  字节码编程
</a></li><li class="dropdown-item"><!----> <a href="/md/middleware/threadpool/default.html" class="nav-link">
  手写线程池
</a></li><li class="dropdown-item"><!----> <a href="/md/middleware/limiter/default.html" class="nav-link">
  分布式限流
</a></li><li class="dropdown-item"><!----> <a href="/md/middleware/independent/default.html" class="nav-link">
  开源项目
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="项目实战" class="dropdown-title"><span class="title">项目实战</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/microservices/springcloudalibaba/2022-04-02-SpringCloudAlibaba专栏开篇.html" class="nav-link">
  SpringCloud Alibaba实战
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="渗透技术" class="dropdown-title"><span class="title">渗透技术</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/hack/environment/2022-04-17-001-安装Kali系统.html" class="nav-link">
  基础环境篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/tools/2022-04-17-001-使用Easy-Creds工具攻击无线网络.html" class="nav-link">
  渗透工具篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/horse/2022-05-02-001-各种一句话木马大全.html" class="nav-link">
  木马篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/sql/2022-05-02-001-sqli-labs-master下载与安装.html" class="nav-link">
  SQL注入篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/shell/2022-05-02-001-各种解析漏洞拿shell.html" class="nav-link">
  漏洞拿Shell篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/crack/2022-05-02-001-使用rarcrack暴力破解RAR-ZIP-7Z压缩包.html" class="nav-link">
  暴力破解篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/bash/2022-05-02-001-3389脚本开启代码(vbs版).html" class="nav-link">
  渗透脚本篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/raising/2022-05-02-001-数据库提权.html" class="nav-link">
  数据与系统提权篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/client/2022-05-02-001-浏览器渗透.html" class="nav-link">
  客户端渗透篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/sociology/2022-05-02-001-Metasploit之社会工程学工具包.html" class="nav-link">
  社会工程学
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/question/2022-05-02-001-HTTP错误4031禁止访问-执行访问被拒绝.html" class="nav-link">
  问题记录篇
</a></li></ul></div></div><div class="nav-item"><a href="/md/interview/2022-04-18-001-面试必问-聊聊JVM性能调优.html" class="nav-link">
  面试必问系列
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="📚PDF" class="dropdown-title"><span class="title">📚PDF</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          出版图书
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/knowledge/book/2022-03-29-深入理解分布式事务.html" class="nav-link">
  《深入理解分布式事务：原理与实战》
</a></li><li class="dropdown-subitem"><a href="/md/knowledge/book/2022-03-29-MySQL技术大全.html" class="nav-link">
  《MySQL技术大全：开发、优化与运维实战》
</a></li><li class="dropdown-subitem"><a href="/md/knowledge/book/2022-03-29-海量数据处理与大数据技术实战.html" class="nav-link">
  《海量数据处理与大数据技术实战》
</a></li></ul></li><li class="dropdown-item"><h4>
          电子书籍
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/knowledge/pdf/2022-03-30-《冰河的渗透实战笔记》电子书，442页，37万字，正式发布.html" class="nav-link">
  冰河的渗透实战笔记
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="关于" class="dropdown-title"><span class="title">关于</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/about/me/about-me.html" class="nav-link">
  关于自己
</a></li><li class="dropdown-item"><!----> <a href="/md/about/study/default.html" class="nav-link">
  关于学习
</a></li><li class="dropdown-item"><!----> <a href="/md/about/job/default.html" class="nav-link">
  关于职场
</a></li></ul></div></div><div class="nav-item"><a href="https://space.bilibili.com/517638832" target="_blank" rel="noopener noreferrer" class="nav-link external">
  B站
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><a href="https://github.com/binghe001/BingheGuide" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Github
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>SpringBoot</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/md/microservices/springboot/default.html" class="sidebar-link">关于我</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>SpringCloudAlibaba</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/md/microservices/springcloudalibaba/2022-04-02-SpringCloudAlibaba专栏开篇.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》专栏开篇啦</a></li><li><a href="/md/microservices/springcloudalibaba/2022-04-04-SA实战·第一篇-专栏设计.html" class="sidebar-link">SA实战 · 《SpringCloud Alibaba实战》专栏设计</a></li><li><a href="/md/microservices/springcloudalibaba/2022-04-09-SA实战-微服务介绍.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》微服务介绍</a></li><li><a href="/md/microservices/springcloudalibaba/2022-04-13-SA实战·项目说明-流程设计-技术选型-模块划分.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》项目说明、流程设计、技术选型与模块划分</a></li><li><a href="/md/microservices/springcloudalibaba/2022-04-18-SA实战-开撸-完成通用模块的开发.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》开撸：完成通用模块的开发</a></li><li><a href="/md/microservices/springcloudalibaba/2022-04-21-SA实战-完成三大微服务的搭建与交互开发.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》快速搭建三大微服务并完成交互开发与测试</a></li><li><a href="/md/microservices/springcloudalibaba/2022-04-25-SA实战-服务治理-实现服务的注册与发现.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》服务治理：实现服务的自动注册与发现</a></li><li><a href="/md/microservices/springcloudalibaba/2022-04-27-SA实战-第8章-服务治理-实现服务调用的负载均衡.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第8章-服务治理：实现服务调用的负载均衡</a></li><li><a href="/md/microservices/springcloudalibaba/2022-04-28-SA实战-第9章-服务容错-服务雪崩与容错方案.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第9章-服务容错：服务雪崩与容错方案</a></li><li><a href="/md/microservices/springcloudalibaba/2022-05-03-SA实战-第10章-服务容错-Fegin整合Sentinel.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第10章-服务容错：项目整合Sentinel实现限流与容错</a></li><li><a href="/md/microservices/springcloudalibaba/2022-05-05-SA实战-第11章-服务容错加餐-Sentinel核心技术与配置规则.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第11章-服务容错加餐：Sentinel核心技术与配置规则（最全使用教程）</a></li><li><a href="/md/microservices/springcloudalibaba/2022-05-08-SA实战-第12章-服务网关-网关概述与核心架构.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第12章-服务网关：网关概述与核心架构</a></li><li><a href="/md/microservices/springcloudalibaba/2022-05-08-SA实战-第13章-服务网关-项目整合SpringCloudGateway.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第13章-服务网关：项目整合SpringCloud Gateway网关</a></li><li><a href="/md/microservices/springcloudalibaba/2022-05-10-SA实战-第14章-服务网关-SpringCloudGateway核心技术.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第14章-服务网关加餐：SpringCloud Gateway核心技术</a></li><li><a href="/md/microservices/springcloudalibaba/2022-05-11-SA实战-第15章-链路追踪-核心原理与解决方案.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第15章-链路追踪：核心原理与解决方案</a></li><li><a href="/md/microservices/springcloudalibaba/2022-05-12-SA实战-第16章-链路追踪-项目整合Sleuth实现链路追踪.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第16章-链路追踪：项目整合Sleuth实现链路追踪</a></li><li><a href="/md/microservices/springcloudalibaba/2022-05-13-SA实战-第17章-链路追踪-Sleuth整合ZipKin.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第17章-链路追踪：Sleuth整合ZipKin</a></li><li><a href="/md/microservices/springcloudalibaba/2022-05-17-SA实战-第18章-消息服务-MQ使用场景与选型对比.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第18章-消息服务：MQ使用场景与选型对比</a></li><li><a href="/md/microservices/springcloudalibaba/2022-05-18-SA实战-第19章-消息服务-项目整合RocketMQ.html" class="active sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第19章-消息服务：项目整合RocketMQ</a></li><li><a href="/md/microservices/springcloudalibaba/2022-05-20-SA实战-第20章-消息服务-RocketMQ核心技术.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第20章-消息服务：RocketMQ核心技术</a></li><li><a href="/md/microservices/springcloudalibaba/2022-05-21-SA实战-第21章-服务配置-服务配置介绍与Nacos核心概念.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第21章-服务配置：服务配置介绍与Nacos核心概念</a></li></ul></section></li></ul> </aside> <div><main class="page"> <div class="theme-default-content content__default"><h1 id="sa实战-·《springcloud-alibaba实战》第19章-消息服务-项目整合rocketmq"><a href="#sa实战-·《springcloud-alibaba实战》第19章-消息服务-项目整合rocketmq" class="header-anchor">#</a> SA实战 ·《SpringCloud Alibaba实战》第19章-消息服务：项目整合RocketMQ</h1> <p><strong>大家好，我是冰河~~</strong></p> <blockquote><p>一不小心《<a href="https://mp.weixin.qq.com/mp/appmsgalbum?__biz=Mzg4MjU0OTM1OA==&amp;action=getalbum&amp;album_id=2337104419664084992&amp;scene=173&amp;from_msgid=2247500408&amp;from_itemidx=1&amp;count=3&amp;nolastread=1#wechat_redirect" target="_blank" rel="noopener noreferrer">SpringCloud Alibaba实战<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>》专栏都更新到第19章了，再不上车就跟不上了，小伙伴们快跟上啊！</p> <p>注意：本项目完整源码加入 <strong><a href="https://public.zsxq.com/groups/48848484411888.html" target="_blank" rel="noopener noreferrer">冰河技术<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></strong> 知识星球即可获取，文末有入场方式。</p></blockquote> <p>在《<a href="https://mp.weixin.qq.com/mp/appmsgalbum?__biz=Mzg4MjU0OTM1OA==&amp;action=getalbum&amp;album_id=2337104419664084992&amp;scene=173&amp;from_msgid=2247500408&amp;from_itemidx=1&amp;count=3&amp;nolastread=1#wechat_redirect" target="_blank" rel="noopener noreferrer">SpringCloud Alibaba实战<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>》专栏前面的文章中，我们实现了用户微服务、商品微服务和订单微服务之间的远程调用，并且实现了服务调用的负载均衡。也基于阿里开源的Sentinel实现了服务的限流与容错，并详细介绍了Sentinel的核心技术与配置规则。简单介绍了服务网关，并对SpringCloud Gateway的核心架构进行了简要说明，也在项目中整合了SpringCloud Gateway网关实现了通过网关访问后端微服务，同时，也基于SpringCloud Gateway整合Sentinel实现了网关的限流功能，详细介绍了SpringCloud Gateway网关的核心技术。在链路追踪章节，我们开始简单介绍了分布式链路追踪技术与解决方案，随后在项目中整合Sleuth实现了链路追踪，并使用Sleuth整合ZipKin实现了分布式链路追踪的可视化 。</p> <p>在消息服务章节，我们介绍了MQ的使用场景，引入MQ后的注意事项以及MQ的选型对比。接下来，我们就在项目中整合RocketMQ。</p> <h2 id="本章总览"><a href="#本章总览" class="header-anchor">#</a> 本章总览</h2> <p><img alt="sa-2022-05-18-019" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-18-019.png" loading="lazy" class="lazy"></p> <h2 id="rocketmq环境准备"><a href="#rocketmq环境准备" class="header-anchor">#</a> RocketMQ环境准备</h2> <p>RocketMQ是阿里开源的消息中间件，目前是Apache下的顶级项目。正式在项目中接入RocketMQ之前，我们需要搭建RocketMQ的环境。这里呢，我把搭建RocketMQ的基础环境分为两个部分：搭建RocketMQ环境和搭建RocketMQ控制台。</p> <p><strong>注意：冰河这里都是先下载RocketMQ的源码和RocketMQ控制台的源码，然后对源码进行编译后，再搭建的。目的也是让小伙伴们能够跟着冰河实现手动编译RocketMQ的源码，另外，编译RocketMQ源码和控制台源码需要JDK1.8+Maven。</strong></p> <h3 id="源码编译安装rocketmq"><a href="#源码编译安装rocketmq" class="header-anchor">#</a> 源码编译安装RocketMQ</h3> <p>（1）到链接<a href="https://github.com/apache/rocketmq/releases/tag/rocketmq-all-4.9.3" target="_blank" rel="noopener noreferrer">https://github.com/apache/rocketmq/releases/tag/rocketmq-all-4.9.3<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>下载RocketMQ 4.9.3版本的源码。下载并解压后的源码如下所示。</p> <p><img alt="sa-2022-05-18-001" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-18-001.png" loading="lazy" class="lazy"></p> <p>（2）打开cmd命令行，进入RocketMQ的解压目录，我这里是E:\Application\RocketMQ\rocketmq-rocketmq-all-4.9.3目录，然后在cmd命令行输入如下命令开始编译打包。</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>mvn clean <span class="token function">install</span> -Dmaven.test.skip<span class="token operator">=</span>true -Prelease-all
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>编译过程如下所示。</p> <p><img alt="sa-2022-05-18-002" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-18-002.png" loading="lazy" class="lazy"></p> <p>编译打包成功后，如下图所示。</p> <p><img alt="sa-2022-05-18-003" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-18-003.png" loading="lazy" class="lazy"></p> <p>（3）编译成功后，会在RocketMQ解压目录下的distribution目录下的target目录下生成RocketMQ的安装包，在我电脑上的目录就是：E:\Application\RocketMQ\rocketmq-rocketmq-all-4.9.3\distribution\target。如下所示。</p> <p><img alt="sa-2022-05-18-004" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-18-004.png" loading="lazy" class="lazy"></p> <p>这样，我们就自己下载RocketMQ的源码，并打包成功了。</p> <p><strong>注意：这里，为了方便，我还是将RocketMQ部署到我本机Windows操作系统上，小伙伴们也可以将之前的Nacos、Sentinel和这次的RocketMQ都部署在Linux操作系统上，部署方式几乎与在Windows操作系统一样，这里，冰河就不再赘述了。</strong></p> <p>（4）将编译出的安装包，解压到电脑的某个目录下，例如我解压后的目录为：E:\Application\microservices\RocketMQ\rocketmq-4.9.3。</p> <p>（5）在RocketMQ的解压目录下的conf目录下修改broker.conf文件，修改后的文件内容如下所示。</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>brokerClusterName <span class="token operator">=</span> DefaultCluster
brokerName <span class="token operator">=</span> broker-a
brokerId <span class="token operator">=</span> <span class="token number">0</span>
deleteWhen <span class="token operator">=</span> 04
fileReservedTime <span class="token operator">=</span> <span class="token number">48</span>
brokerRole <span class="token operator">=</span> ASYNC_MASTER
flushDiskType <span class="token operator">=</span> ASYNC_FLUSH

<span class="token comment"># 自动创建Topic</span>
<span class="token assign-left variable">autoCreateTopicEnable</span><span class="token operator">=</span>true
<span class="token comment"># nameServ地址</span>
<span class="token assign-left variable">namesrvAddr</span><span class="token operator">=</span><span class="token number">127.0</span>.0.1:9876
<span class="token comment"># 存储路径</span>
<span class="token assign-left variable">storePathRootDir</span><span class="token operator">=</span>E:/RocketMQ/data/rocketmq/dataDir
<span class="token comment"># commitLog路径</span>
<span class="token assign-left variable">storePathCommitLog</span><span class="token operator">=</span>E:/RocketMQ/data/rocketmq/dataDir/commitlog
<span class="token comment"># 消息队列存储路径</span>
<span class="token assign-left variable">storePathConsumeQueue</span><span class="token operator">=</span>E:/RocketMQ/data/rocketmq/dataDir/consumequeue
<span class="token comment"># 消息索引存储路径</span>
<span class="token assign-left variable">storePathIndex</span><span class="token operator">=</span>E:/RocketMQ/data/rocketmq/dataDir/index
<span class="token comment"># checkpoint文件路径</span>
<span class="token assign-left variable">storeCheckpoint</span><span class="token operator">=</span>E:/RocketMQ/data/rocketmq/dataDir/checkpoint
<span class="token comment"># abort文件存储路径</span>
<span class="token assign-left variable">abortFile</span><span class="token operator">=</span>E:/RocketMQ/data/rocketmq/dataDir/abort
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br></div></div><p>小伙伴们可以根据自己的实际情况，自行修改上述文件中配置的目录地址。</p> <p>（6）非常重要的一步，在启动RocketMQ之前，需要配置下ROCKETMQ_HOME环境变量，否则在启动RocketMQ的时候，会提示如下错误信息。</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>E:<span class="token punctuation">\</span>Application<span class="token punctuation">\</span>microservices<span class="token punctuation">\</span>RocketMQ<span class="token punctuation">\</span>rocketmq-4.9.3<span class="token punctuation">\</span>bin<span class="token operator">&gt;</span>mqnamesrv.cmd
Please <span class="token builtin class-name">set</span> the ROCKETMQ_HOME variable <span class="token keyword">in</span> your environment<span class="token operator">!</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p><strong>提示：设置ROCKETMQ_HOME环境变量。</strong></p> <p>接下来，就在系统环境变量中，设置下ROCKETMQ_HOME的环境变量，如下所示。</p> <p><img alt="sa-2022-05-18-005" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-18-005.png" loading="lazy" class="lazy"></p> <p>（7）配置完RocketMQ的环境变量后，打开cmd命令行，进入RocketMQ的bin目录，例如，我电脑的目录是：E:\Application\microservices\RocketMQ\rocketmq-4.9.3\bin。执行<code>mqnamesrv.cmd</code>命令启动NameServer，如下所示。</p> <p><img alt="sa-2022-05-18-006" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-18-006.png" loading="lazy" class="lazy"></p> <p>打印出如下信息，说明RocketMQ的NameServer启动成功了。</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>The Name Server boot success. <span class="token assign-left variable">serializeType</span><span class="token operator">=</span>JSON
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>（8）重新打开一个cmd命令行，进入RocketMQ的bin目录，输入<code>mqbroker.cmd -n localhost:9876</code>命令启动RocketMQ的Broker服务，如下所示。</p> <p><img alt="sa-2022-05-18-007" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-18-007.png" loading="lazy" class="lazy"></p> <p>打印出如下信息，说明RocketMQ的Broker服务启动成功了。</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>boot success. <span class="token assign-left variable">serializeType</span><span class="token operator">=</span>JSON and name server is localhost:9876
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="测试rocketmq环境"><a href="#测试rocketmq环境" class="header-anchor">#</a> 测试RocketMQ环境</h3> <p>RocketMQ内置了大量的测试案例，并且这些测试案例可以通过RocketMQ的bin目录下的tools.cmd命令进行测试。接下来，我们就使用RocketMQ自带的tools.cmd命令测试RocketMQ的环境。</p> <p>（1）启动生产者程序向RocketMQ发送消息。</p> <p>重新打开cmd命令行，进入RocketMQ的bin目录，在命令行输入如下命令调用RocketMQ自带的生产者程序向RocketMQ发送消息。</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token builtin class-name">set</span> <span class="token assign-left variable">NAMESRV_ADDR</span><span class="token operator">=</span>localhost:9876
tools.cmd org.apache.rocketmq.example.quickstart.Producer
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>可以看到，执行完上述两条命令后，生产者程序开始向RocketMQ发送消息。</p> <p><img alt="sa-2022-05-18-008" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-18-008.png" loading="lazy" class="lazy"></p> <p>（2）启动消费者程序消费RocketMQ中的消息。</p> <p>重新打开cmd命令行，进入RocketMQ的bin目录，在命令行输入如下命令调用RocketMQ自带的消费者程序消费RocketMQ中的消息。</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token builtin class-name">set</span> <span class="token assign-left variable">NAMESRV_ADDR</span><span class="token operator">=</span>localhost:9876
tools.cmd org.apache.rocketmq.example.quickstart.Consumer
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>可以看到，执行完上述两条命令后，消费者程序开始消费RocketMQ中的消息。</p> <p><img alt="sa-2022-05-18-009" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-18-009.png" loading="lazy" class="lazy"></p> <p>说明我们使用源码编译搭建RocketMQ环境成功了。</p> <h3 id="源码编译rocketmq控制台"><a href="#源码编译rocketmq控制台" class="header-anchor">#</a> 源码编译RocketMQ控制台</h3> <p>这里需要注意的是：RocketMQ控制台本质上是一个SpringBoot程序，启动后默认监听的端口是8080。RocketMQ的新版控制台已经从RocketMQ的rocketmq-externals项目中分离出来了。也就是说，新版的RocketMQ控制台已经从https://github.com/apache/rocketmq-externals链接所示的项目中分离出来，新版控制台的链接地址为：https://github.com/apache/rocketmq-dashboard。</p> <p>（1）从链接https://github.com/apache/rocketmq-dashboard下载新版的RocketMQ控制台源码。下载后解压。</p> <p>（2）进入到RocketMQ控制台源码解压目录的src/main/resources目录下，编辑application.yml文件，修改<code>namesrvAddrs</code>地址，去掉多余的namesrvAddrs地址。</p> <p>application.yml文件中原来的配置如下所示。</p> <div class="language-yaml line-numbers-mode"><pre class="language-yaml"><code><span class="token key atrule">rocketmq</span><span class="token punctuation">:</span>
  <span class="token key atrule">config</span><span class="token punctuation">:</span>
    <span class="token comment"># if this value is empty,use env value rocketmq.config.namesrvAddr  NAMESRV_ADDR | now, default localhost:9876</span>
    <span class="token comment"># configure multiple namesrv addresses to manage multiple different clusters</span>
    <span class="token key atrule">namesrvAddrs</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> 127.0.0.1<span class="token punctuation">:</span><span class="token number">9876</span>
      <span class="token punctuation">-</span> 127.0.0.2<span class="token punctuation">:</span><span class="token number">9876</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><p>将127.0.0.2:9876删除或者注释掉，如下所示。</p> <div class="language-yaml line-numbers-mode"><pre class="language-yaml"><code><span class="token key atrule">rocketmq</span><span class="token punctuation">:</span>
  <span class="token key atrule">config</span><span class="token punctuation">:</span>
    <span class="token comment"># if this value is empty,use env value rocketmq.config.namesrvAddr  NAMESRV_ADDR | now, default localhost:9876</span>
    <span class="token comment"># configure multiple namesrv addresses to manage multiple different clusters</span>
    <span class="token key atrule">namesrvAddrs</span><span class="token punctuation">:</span>
      <span class="token punctuation">-</span> 127.0.0.1<span class="token punctuation">:</span><span class="token number">9876</span>
    <span class="token comment">#  - 127.0.0.2:9876</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><p>RocketMQ控制台启动时默认监听的端口是8080，由于我们项目中订单微服务监听的端口也是8080，所以，将RocketMQ控制台监听的端口修改为10003，修改前的配置如下所示。</p> <div class="language-yaml line-numbers-mode"><pre class="language-yaml"><code><span class="token key atrule">server</span><span class="token punctuation">:</span>
  <span class="token key atrule">port</span><span class="token punctuation">:</span> <span class="token number">8080</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>修改后的配置如下所示。</p> <div class="language-yaml line-numbers-mode"><pre class="language-yaml"><code><span class="token key atrule">server</span><span class="token punctuation">:</span>
  <span class="token key atrule">port</span><span class="token punctuation">:</span> <span class="token number">10003</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>（3）修改完application.yml文件后，打开cmd命令行，进入RocketMQ控制台源码的根目录，输入如下Maven命令开始编译RocketMQ控制台的源码。</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>mvn clean <span class="token function">install</span> -Dmaven.test.skip<span class="token operator">=</span>true
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>编译过程如下所示。</p> <p><img alt="sa-2022-05-18-010" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-18-010.png" loading="lazy" class="lazy"></p> <p>（4）编译完成后，会在RocketMQ控制台源码的根目录下生成target目录，如下所示。</p> <p><img alt="sa-2022-05-18-011" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-18-011.png" loading="lazy" class="lazy"></p> <p>进入target目录后，可以看到生成了rocketmq-dashboard-1.0.1-SNAPSHOT.jar文件，如下所示。</p> <p><img alt="sa-2022-05-18-012" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-18-012.png" loading="lazy" class="lazy"></p> <p>这个jar文件就是RocketMQ控制台的运行文件。</p> <p>（5）重新打开cmd命令行，进入rocketmq-dashboard-1.0.1-SNAPSHOT.jar文件所在的命令，在命令行直接输入如下命令启动RocketMQ控制台程序。</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>java -jar rocketmq-dashboard-1.0.1-SNAPSHOT.jar
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="验证rocketmq控制台"><a href="#验证rocketmq控制台" class="header-anchor">#</a> 验证RocketMQ控制台</h3> <p>在浏览器中输入<code>http://localhost:10003</code>后，出现如下画面说明RocketMQ启动成功。</p> <p><img alt="sa-2022-05-18-013" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-18-013.png" loading="lazy" class="lazy"></p> <p>界面默认是英文，我们也可以点击右上角的<code>changeLanguage</code>切换语言，切换成中文显示，如下所示。</p> <p><img alt="sa-2022-05-18-014" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-18-014.png" loading="lazy" class="lazy"></p> <p>选择主题菜单想后如下所示。</p> <p><img alt="sa-2022-05-18-015" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-18-015.png" loading="lazy" class="lazy"></p> <p>可以看到目前RocketMQ中存在一个名称为TopicTest的主题，点击TopicTest主题的状态按钮，如下所示。</p> <p><img alt="sa-2022-05-18-016" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-18-016.png" loading="lazy" class="lazy"></p> <p>会显示TopicTest主题的消息队列信息，如下所示。</p> <p><img alt="sa-2022-05-18-017" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-18-017.png" loading="lazy" class="lazy"></p> <p>可以看到，正确显示出了TopicTest主题的消息队列信息，说明RocketMQ控制台启动成功了。</p> <h2 id="编码测试rocketmq"><a href="#编码测试rocketmq" class="header-anchor">#</a> 编码测试RocketMQ</h2> <p>我们使用RocketMQ自带的生产者和消费者程序实现了消息的生成与消费，为了让小伙伴们能够更加直观的感受到消息中间件在项目中的作用，接下来，我们自己编码测试下RocketMQ。</p> <h3 id="导入rocketmq依赖"><a href="#导入rocketmq依赖" class="header-anchor">#</a> 导入RocketMQ依赖</h3> <p>在用户微服务shop-user的pom.xml中，添加RocketMQ相关的依赖，如下所示。</p> <div class="language-xml line-numbers-mode"><pre class="language-xml"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>org.apache.rocketmq<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>rocketmq-spring-boot-starter<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">&gt;</span></span>2.0.3<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>org.apache.rocketmq<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>rocketmq-client<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">&gt;</span></span>4.5.2<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><h3 id="编写生产者代码"><a href="#编写生产者代码" class="header-anchor">#</a> 编写生产者代码</h3> <p>在用户微服务的sec/test/java目录下新建<code>io.binghe.shop.rocketmq.test</code>包，在包下创建RocketMQProducer类，作为RocketMQ的生产者，代码如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token comment">/**
 * @author binghe
 * @version 1.0.0
 * @description RocketMQ生产者
 */</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">RocketMQProducer</span> <span class="token punctuation">{</span>

    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token keyword">throws</span> <span class="token class-name">Exception</span> <span class="token punctuation">{</span>
        <span class="token comment">//创建消息生产者</span>
        <span class="token class-name">DefaultMQProducer</span> producer <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">DefaultMQProducer</span><span class="token punctuation">(</span><span class="token string">&quot;bingheProducerGroup&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">//设置NameServer地址</span>
        producer<span class="token punctuation">.</span><span class="token function">setNamesrvAddr</span><span class="token punctuation">(</span><span class="token string">&quot;127.0.0.1:9876&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">//启动生产者</span>
        producer<span class="token punctuation">.</span><span class="token function">start</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">//构建消息对象</span>
        <span class="token class-name">Message</span> message <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Message</span><span class="token punctuation">(</span><span class="token string">&quot;bingheTopic&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;bingheTag&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;Hello RocketMQ&quot;</span><span class="token punctuation">.</span><span class="token function">getBytes</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;生产者发出的消息为：&quot;</span> <span class="token operator">+</span> <span class="token class-name">JSONObject</span><span class="token punctuation">.</span><span class="token function">toJSONString</span><span class="token punctuation">(</span>message<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">//发送消息并接收结果</span>
        <span class="token class-name">SendResult</span> sendResult <span class="token operator">=</span> producer<span class="token punctuation">.</span><span class="token function">send</span><span class="token punctuation">(</span>message<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">//打印结果信息</span>
        <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;生产者收到的发送结果信息为：&quot;</span> <span class="token operator">+</span> <span class="token class-name">JSONObject</span><span class="token punctuation">.</span><span class="token function">toJSONString</span><span class="token punctuation">(</span>sendResult<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">//关闭生产者</span>
        producer<span class="token punctuation">.</span><span class="token function">shutdown</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br></div></div><p>生产者的代码比较简单，这里就不再赘述了。</p> <h3 id="编写消费者代码"><a href="#编写消费者代码" class="header-anchor">#</a> 编写消费者代码</h3> <p>在<code>io.binghe.shop.rocketmq.test</code>包下新建RocketMQConsumer类，作为RocketMQ的消费者，代码如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token comment">/**
 * @author binghe
 * @version 1.0.0
 * @description RocketMQ消费者
 */</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">RocketMQConsumer</span> <span class="token punctuation">{</span>

   <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token keyword">throws</span> <span class="token class-name">Exception</span> <span class="token punctuation">{</span>
       <span class="token keyword">try</span><span class="token punctuation">{</span>
           <span class="token comment">//创建消息消费者</span>
           <span class="token class-name">DefaultMQPushConsumer</span> consumer <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">DefaultMQPushConsumer</span><span class="token punctuation">(</span><span class="token string">&quot;bingheConsumerGroup&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
           <span class="token comment">//设置NameServer地址</span>
           consumer<span class="token punctuation">.</span><span class="token function">setNamesrvAddr</span><span class="token punctuation">(</span><span class="token string">&quot;127.0.0.1:9876&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
           <span class="token comment">//订阅bingheTopic主题</span>
           consumer<span class="token punctuation">.</span><span class="token function">subscribe</span><span class="token punctuation">(</span><span class="token string">&quot;bingheTopic&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;*&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
           <span class="token comment">//设置消息监听，当收到消息时RocketMQ会回调消息监听</span>
           consumer<span class="token punctuation">.</span><span class="token function">registerMessageListener</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">MessageListenerConcurrently</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
               <span class="token annotation punctuation">@Override</span>
               <span class="token keyword">public</span> <span class="token class-name">ConsumeConcurrentlyStatus</span> <span class="token function">consumeMessage</span><span class="token punctuation">(</span><span class="token class-name">List</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">MessageExt</span><span class="token punctuation">&gt;</span></span> list<span class="token punctuation">,</span>
                                                               <span class="token class-name">ConsumeConcurrentlyContext</span> consumeConcurrentlyContext<span class="token punctuation">)</span> <span class="token punctuation">{</span>
                   <span class="token comment">//打印消息消费者收到的RocketMQ消息</span>
                   <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;消费者收到的消息为：&quot;</span> <span class="token operator">+</span> list<span class="token punctuation">)</span><span class="token punctuation">;</span>
                   <span class="token comment">//返回消息消费成功的标识</span>
                   <span class="token keyword">return</span> <span class="token class-name">ConsumeConcurrentlyStatus</span><span class="token punctuation">.</span>CONSUME_SUCCESS<span class="token punctuation">;</span>
               <span class="token punctuation">}</span>
           <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
           <span class="token comment">//启动消费者</span>
           consumer<span class="token punctuation">.</span><span class="token function">start</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
           <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">&quot;消费者启动成功&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
       <span class="token punctuation">}</span><span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">Exception</span> e<span class="token punctuation">)</span><span class="token punctuation">{</span>
           e<span class="token punctuation">.</span><span class="token function">printStackTrace</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
       <span class="token punctuation">}</span>
   <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br></div></div><h3 id="测试消息的生产与消费"><a href="#测试消息的生产与消费" class="header-anchor">#</a> 测试消息的生产与消费</h3> <p>（1）为了便于观察，这里我们先启动消费者程序RocketMQConsumer，启动RocketMQConsumer后会在IDEA的控制台打印如下信息。</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>消费者启动成功
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>说明消费者启动成功了。</p> <p>（2）运行生产者程序RocketMQProducer，运行后RocketMQProducer程序控制台会输出如下信息。</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>生产者发出的消息为：<span class="token punctuation">{</span><span class="token string">&quot;body&quot;</span><span class="token builtin class-name">:</span><span class="token string">&quot;SGVsbG8gUm9ja2V0TVE=&quot;</span>,<span class="token string">&quot;delayTimeLevel&quot;</span>:0,<span class="token string">&quot;flag&quot;</span>:0,<span class="token string">&quot;properties&quot;</span>:<span class="token punctuation">{</span><span class="token string">&quot;WAIT&quot;</span><span class="token builtin class-name">:</span><span class="token string">&quot;true&quot;</span>,<span class="token string">&quot;TAGS&quot;</span><span class="token builtin class-name">:</span><span class="token string">&quot;bingheTag&quot;</span><span class="token punctuation">}</span>,<span class="token string">&quot;tags&quot;</span><span class="token builtin class-name">:</span><span class="token string">&quot;bingheTag&quot;</span>,<span class="token string">&quot;topic&quot;</span><span class="token builtin class-name">:</span><span class="token string">&quot;bingheTopic&quot;</span>,<span class="token string">&quot;waitStoreMsgOK&quot;</span>:true<span class="token punctuation">}</span>
生产者收到的发送结果信息为：<span class="token punctuation">{</span><span class="token string">&quot;messageQueue&quot;</span>:<span class="token punctuation">{</span><span class="token string">&quot;brokerName&quot;</span><span class="token builtin class-name">:</span><span class="token string">&quot;DESKTOP-PSKC7T1&quot;</span>,<span class="token string">&quot;queueId&quot;</span>:1,<span class="token string">&quot;topic&quot;</span><span class="token builtin class-name">:</span><span class="token string">&quot;bingheTopic&quot;</span><span class="token punctuation">}</span>,<span class="token string">&quot;msgId&quot;</span><span class="token builtin class-name">:</span><span class="token string">&quot;C0A8006F538418B4AAC25B9EDDAC0000&quot;</span>,<span class="token string">&quot;offsetMsgId&quot;</span><span class="token builtin class-name">:</span><span class="token string">&quot;C0A8B80100002A9F0000000000036B16&quot;</span>,<span class="token string">&quot;queueOffset&quot;</span>:2,<span class="token string">&quot;regionId&quot;</span><span class="token builtin class-name">:</span><span class="token string">&quot;DefaultRegion&quot;</span>,<span class="token string">&quot;sendStatus&quot;</span><span class="token builtin class-name">:</span><span class="token string">&quot;SEND_OK&quot;</span>,<span class="token string">&quot;traceOn&quot;</span>:true<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>说明生产者程序RocketMQProducer成功将消息发送到RocketMQ。</p> <p>（3）接下来，再看下消费者程序RocketMQConsumer的控制台，如下所示。</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>消费者收到的消息为：<span class="token punctuation">[</span>MessageExt <span class="token punctuation">[</span>queueId<span class="token operator">=</span><span class="token number">1</span>, <span class="token assign-left variable">storeSize</span><span class="token operator">=</span><span class="token number">206</span>, <span class="token assign-left variable">queueOffset</span><span class="token operator">=</span><span class="token number">2</span>, <span class="token assign-left variable">sysFlag</span><span class="token operator">=</span><span class="token number">0</span>, <span class="token assign-left variable">bornTimestamp</span><span class="token operator">=</span><span class="token number">1652871538093</span>, <span class="token assign-left variable">bornHost</span><span class="token operator">=</span>/192.168.184.1:52915, <span class="token assign-left variable">storeTimestamp</span><span class="token operator">=</span><span class="token number">1652871538099</span>, <span class="token assign-left variable">storeHost</span><span class="token operator">=</span>/192.168.184.1:10911, <span class="token assign-left variable">msgId</span><span class="token operator">=</span>C0A8B80100002A9F0000000000036B16, <span class="token assign-left variable">commitLogOffset</span><span class="token operator">=</span><span class="token number">224022</span>, <span class="token assign-left variable">bodyCRC</span><span class="token operator">=</span><span class="token number">1774740973</span>, <span class="token assign-left variable">reconsumeTimes</span><span class="token operator">=</span><span class="token number">0</span>, <span class="token assign-left variable">preparedTransactionOffset</span><span class="token operator">=</span><span class="token number">0</span>, toString<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">=</span>Message<span class="token punctuation">{</span>topic<span class="token operator">=</span><span class="token string">'bingheTopic'</span>, <span class="token assign-left variable">flag</span><span class="token operator">=</span><span class="token number">0</span>, <span class="token assign-left variable">properties</span><span class="token operator">=</span><span class="token punctuation">{</span>MIN_OFFSET<span class="token operator">=</span><span class="token number">0</span>, <span class="token assign-left variable">MAX_OFFSET</span><span class="token operator">=</span><span class="token number">3</span>, <span class="token assign-left variable">CONSUME_START_TIME</span><span class="token operator">=</span><span class="token number">1652871538103</span>, <span class="token assign-left variable">UNIQ_KEY</span><span class="token operator">=</span>C0A8006F538418B4AAC25B9EDDAC0000, <span class="token assign-left variable">CLUSTER</span><span class="token operator">=</span>DefaultCluster, <span class="token assign-left variable">WAIT</span><span class="token operator">=</span>true, <span class="token assign-left variable">TAGS</span><span class="token operator">=</span>bingheTag<span class="token punctuation">}</span>, <span class="token assign-left variable">body</span><span class="token operator">=</span><span class="token punctuation">[</span><span class="token number">72</span>, <span class="token number">101</span>, <span class="token number">108</span>, <span class="token number">108</span>, <span class="token number">111</span>, <span class="token number">32</span>, <span class="token number">82</span>, <span class="token number">111</span>, <span class="token number">99</span>, <span class="token number">107</span>, <span class="token number">101</span>, <span class="token number">116</span>, <span class="token number">77</span>, <span class="token number">81</span><span class="token punctuation">]</span>, <span class="token assign-left variable">transactionId</span><span class="token operator">=</span><span class="token string">'null'</span><span class="token punctuation">}</span><span class="token punctuation">]</span><span class="token punctuation">]</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>说明生成者发送到RocketMQ的消息，被消费者成功消费到了。</p> <h2 id="项目整合rocketmq"><a href="#项目整合rocketmq" class="header-anchor">#</a> 项目整合RocketMQ</h2> <p>我们在项目中模拟一个用户成功下单后，为用户发送通知，通知用户下单成功的逻辑，具体的流程就是下单成功后将订单的信息发送到RocketMQ，然后用户微服务订阅RocketMQ的消息，接收到消息后进行打印。</p> <h3 id="用户微服务整合rocketmq"><a href="#用户微服务整合rocketmq" class="header-anchor">#</a> 用户微服务整合RocketMQ</h3> <p>（1）编码测试RocketMQ时，导入了RocketMQ的依赖，这里就不用再次导入了。</p> <p>（2）在用户微服务shop-user的application.yml文件中添加如下RocketMQ的配置。</p> <div class="language-yaml line-numbers-mode"><pre class="language-yaml"><code><span class="token key atrule">rocketmq</span><span class="token punctuation">:</span>
  <span class="token key atrule">name-server</span><span class="token punctuation">:</span> 127.0.0.1<span class="token punctuation">:</span><span class="token number">9876</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>（3）在用户微服务shop-user中创建<code>io.binghe.shop.user.rocketmq</code>包，在包下创建RocketConsumeListener，实现org.apache.rocketmq.spring.core.RocketMQListener接口，具体代码如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token comment">/**
 * @author binghe
 * @version 1.0.0
 * @description 监听消费
 */</span>
<span class="token annotation punctuation">@Slf4j</span>
<span class="token annotation punctuation">@Component</span>
<span class="token annotation punctuation">@RocketMQMessageListener</span><span class="token punctuation">(</span>consumerGroup <span class="token operator">=</span> <span class="token string">&quot;user-group&quot;</span><span class="token punctuation">,</span> topic <span class="token operator">=</span> <span class="token string">&quot;order-topic&quot;</span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">RocketConsumeListener</span> <span class="token keyword">implements</span> <span class="token class-name">RocketMQListener</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Order</span><span class="token punctuation">&gt;</span></span> <span class="token punctuation">{</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">onMessage</span><span class="token punctuation">(</span><span class="token class-name">Order</span> order<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        log<span class="token punctuation">.</span><span class="token function">info</span><span class="token punctuation">(</span><span class="token string">&quot;用户微服务收到了订单信息：{}&quot;</span><span class="token punctuation">,</span> <span class="token class-name">JSONObject</span><span class="token punctuation">.</span><span class="token function">toJSONString</span><span class="token punctuation">(</span>order<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br></div></div><p>其中，RocketConsumeListener类上的@RocketMQMessageListener注解，表示当前类是一个RocketMQ的消费者，在@RocketMQMessageListener注解中配置了消费者组为user-group，主题为order-topic。</p> <p>至此，用户微服务整合RocketMQ完毕。</p> <h3 id="订单微服务整合rocketmq"><a href="#订单微服务整合rocketmq" class="header-anchor">#</a> 订单微服务整合RocketMQ</h3> <p>（1）在订单微服务shop-order的pom.xml文件中添加RocketMQ的依赖，如下所示。</p> <div class="language-xml line-numbers-mode"><pre class="language-xml"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>org.apache.rocketmq<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>rocketmq-spring-boot-starter<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">&gt;</span></span>2.0.3<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">&gt;</span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>org.apache.rocketmq<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>rocketmq-client<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">&gt;</span></span>4.5.2<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><p>（2）在订单微服务shop-order的application.yml文件中添加如下配置。</p> <div class="language-yaml line-numbers-mode"><pre class="language-yaml"><code><span class="token key atrule">rocketmq</span><span class="token punctuation">:</span>
  <span class="token key atrule">name-server</span><span class="token punctuation">:</span> 127.0.0.1<span class="token punctuation">:</span><span class="token number">9876</span>
  <span class="token key atrule">producer</span><span class="token punctuation">:</span>
    <span class="token key atrule">group</span><span class="token punctuation">:</span> order<span class="token punctuation">-</span>group
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p>（3）将<code>io.binghe.shop.order.service.impl.OrderServiceV6Impl</code>类，复制一份成<code>io.binghe.shop.order.service.impl.OrderServiceV7Impl</code>类，接下来，在<code>io.binghe.shop.order.service.impl.OrderServiceV7Impl</code>类中操作。</p> <p>将<code>io.binghe.shop.order.service.impl.OrderServiceV7Impl</code>类上的@Service注解中的名称修改为orderServiceV7，如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token annotation punctuation">@Slf4j</span>
<span class="token annotation punctuation">@Service</span><span class="token punctuation">(</span><span class="token string">&quot;orderServiceV7&quot;</span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">OrderServiceV7Impl</span> <span class="token keyword">implements</span> <span class="token class-name">OrderService</span> <span class="token punctuation">{</span>
    <span class="token comment">//省略具体代码</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p>（4）在<code>io.binghe.shop.order.service.impl.OrderServiceV7Impl</code>类中，注入RocketMQTemplate对象，如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token annotation punctuation">@Autowired</span>
<span class="token keyword">private</span> <span class="token class-name">RocketMQTemplate</span> rocketMQTemplate<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>（5）在<code>io.binghe.shop.order.service.impl.OrderServiceV7Impl#saveOrder()</code>方法中，提交订单成功后将订单信息写入RocketMQ，如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token annotation punctuation">@Override</span>
<span class="token annotation punctuation">@Transactional</span><span class="token punctuation">(</span>rollbackFor <span class="token operator">=</span> <span class="token class-name">Exception</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">saveOrder</span><span class="token punctuation">(</span><span class="token class-name">OrderParams</span> orderParams<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">//省略上面所有代码</span>
    rocketMQTemplate<span class="token punctuation">.</span><span class="token function">convertAndSend</span><span class="token punctuation">(</span><span class="token string">&quot;order-topic&quot;</span><span class="token punctuation">,</span> order<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><p>（6）在<code>io.binghe.shop.order.controller.OrderController</code>中，将注入的OrderService的名称修改成orderServiceV7，如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token annotation punctuation">@Autowired</span>
<span class="token annotation punctuation">@Qualifier</span><span class="token punctuation">(</span>value <span class="token operator">=</span> <span class="token string">&quot;orderServiceV7&quot;</span><span class="token punctuation">)</span>
<span class="token keyword">private</span> <span class="token class-name">OrderService</span> orderService<span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p><strong>注意：订单微服务shop-order中，修改后的代码见源码工程，冰河在这里不再粘贴完整的源代码。</strong></p> <h3 id="测试项目整合的rocketmq"><a href="#测试项目整合的rocketmq" class="header-anchor">#</a> 测试项目整合的RocketMQ</h3> <p>（1）分别启动Nacos，Sentinel，ZipKin和RocketMQ。</p> <p>（2）分别启动用户微服务、商品微服务、订单微服务和网关服务。</p> <p>（3）在浏览器中输入<code>localhost:10001/server-order/order/submit_order?userId=1001&amp;productId=1001&amp;count=1</code>，如下所示。</p> <p><img alt="sa-2022-05-18-018" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-05-18-018.png" loading="lazy" class="lazy"></p> <p>（4）查看用户微服务shop-user的控制台，发现会输出订单的信息，如下所示。</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token number">2022</span>-05-18 <span class="token number">20</span>:37:26.440  INFO <span class="token punctuation">[</span>server-user,,,<span class="token punctuation">]</span> <span class="token number">18064</span> --- <span class="token punctuation">[</span>MessageThread_1<span class="token punctuation">]</span> i.b.s.u.rocketmq.RocketConsumeListener   <span class="token builtin class-name">:</span> 用户微服务收到了订单信息：<span class="token punctuation">{</span><span class="token string">&quot;address&quot;</span><span class="token builtin class-name">:</span><span class="token string">&quot;北京&quot;</span>,<span class="token string">&quot;id&quot;</span>:13176882400989185,<span class="token string">&quot;phone&quot;</span><span class="token builtin class-name">:</span><span class="token string">&quot;13212345678&quot;</span>,<span class="token string">&quot;totalPrice&quot;</span>:2399.00,<span class="token string">&quot;userId&quot;</span>:1001,<span class="token string">&quot;username&quot;</span><span class="token builtin class-name">:</span><span class="token string">&quot;binghe&quot;</span><span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>说明项目中成功集成了RocketMQ。</p> <p><strong>好了，今天我们就到儿吧，限于篇幅，文中并未给出完整的案例源代码，想要完整源代码的小伙伴可加入【冰河技术】知识星球获取源码。也可以加我微信：hacker_binghe，一起交流技术。</strong></p> <p><strong>另外，一不小心就写了19章了，小伙伴们你们再不上车就真的跟不上了！！！</strong></p> <h2 id="关于星球"><a href="#关于星球" class="header-anchor">#</a> 关于星球</h2> <p>最近，冰河创建了【冰河技术】知识星球，《<a href="https://mp.weixin.qq.com/mp/appmsgalbum?__biz=Mzg4MjU0OTM1OA==&amp;action=getalbum&amp;album_id=2337104419664084992&amp;scene=173&amp;from_msgid=2247500214&amp;from_itemidx=1&amp;count=3&amp;nolastread=1#wechat_redirect" target="_blank" rel="noopener noreferrer">SpringCloud Alibaba实战<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>》专栏的源码获取方式会放到知识星球中，同时在微信上会创建专门的知识星球群，冰河会在知识星球上和星球群里解答球友的提问。</p> <p>今天，【冰河技术】知识星球再开放200张优惠券，还没上车的小伙伴赶紧啦，再不上车就跟不上啦！！</p> <h3 id="星球提供的服务"><a href="#星球提供的服务" class="header-anchor">#</a> 星球提供的服务</h3> <p>冰河整理了星球提供的一些服务，如下所示。</p> <p>加入星球，你将获得：</p> <p>1.学习SpringCloud Alibaba实战项目—从零开发微服务项目</p> <p>2.学习高并发、大流量业务场景的解决方案，体验大厂真正的高并发、大流量的业务场景</p> <p>3.学习进大厂必备技能：性能调优、并发编程、分布式、微服务、框架源码、中间件开发、项目实战</p> <p>4.提供站点 https://binghe001.github.io 所有学习内容的指导、帮助</p> <p>5.GitHub：https://github.com/binghe001/BingheGuide - 非常有价值的技术资料仓库，包括冰河所有的博客开放案例代码</p> <p>6.可以发送你的简历到我的邮箱，提供简历批阅服务</p> <p>7.提供技术问题、系统架构、学习成长、晋升答辩等各项内容的回答</p> <p>8.定期的整理和分享出各类专属星球的技术小册、电子书、编程视频、PDF文件</p> <p>9.定期组织技术直播分享，传道、授业、解惑，指导阶段瓶颈突破技巧</p> <h3 id="星球门票价格"><a href="#星球门票价格" class="header-anchor">#</a> 星球门票价格</h3> <p>星球目前的门票价格50元，随着每次加入新实战项目和分享硬核技术上调入场价格。</p> <p><strong>特别提醒：</strong> 苹果用户进圈或续费，请加微信「hacker_binghe」扫二维码，或者去公众号「冰河技术」回复「星球」扫二维码进圈。</p> <p>最后，小伙伴们可以扫描或者长按下图中的二维码加入星球，也可以在 <strong>冰河技术</strong> 公众号回复 “ <strong>星球</strong> ” ，领取入场优惠券。</p> <p><img alt="sa-2022-04-21-007" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-04-28-008.png" loading="lazy" class="lazy"></p> <p><strong>好了，今天就到这儿吧，我是冰河，我们下期见~~</strong></p> <h2 id="写在最后"><a href="#写在最后" class="header-anchor">#</a> 写在最后</h2> <blockquote><p>如果你觉得冰河写的还不错，请微信搜索并关注「 <strong>冰河技术</strong> 」微信公众号，跟冰河学习高并发、分布式、微服务、大数据、互联网和云原生技术，「 <strong>冰河技术</strong> 」微信公众号更新了大量技术专题，每一篇技术文章干货满满！不少读者已经通过阅读「 <strong>冰河技术</strong> 」微信公众号文章，吊打面试官，成功跳槽到大厂；也有不少读者实现了技术上的飞跃，成为公司的技术骨干！如果你也想像他们一样提升自己的能力，实现技术能力的飞跃，进大厂，升职加薪，那就关注「 <strong>冰河技术</strong> 」微信公众号吧，每天更新超硬核技术干货，让你对如何提升技术能力不再迷茫！</p></blockquote> <p><img alt="" data-src="https://img-blog.csdnimg.cn/20200906013715889.png" loading="lazy" class="lazy"></p></div> <footer class="page-edit"><div class="edit-link"><a href="https://github.com/binghe001/BingheGuide/edit/master/docs/md/microservices/springcloudalibaba/2022-05-18-SA实战-第19章-消息服务-项目整合RocketMQ.md" target="_blank" rel="noopener noreferrer">在 GitHub 上编辑此页</a> <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></div> <div class="last-updated"><span class="prefix">上次更新: </span> <span class="time">2022/5/23</span></div></footer> <div class="page-nav"><p class="inner"><span class="prev">
        ←
        <a href="/md/microservices/springcloudalibaba/2022-05-17-SA实战-第18章-消息服务-MQ使用场景与选型对比.html" class="prev">
          SA实战 ·《SpringCloud Alibaba实战》第18章-消息服务：MQ使用场景与选型对比
        </a></span> <span class="next"><a href="/md/microservices/springcloudalibaba/2022-05-20-SA实战-第20章-消息服务-RocketMQ核心技术.html">
          SA实战 ·《SpringCloud Alibaba实战》第20章-消息服务：RocketMQ核心技术
        </a>
        →
      </span></p></div> </main></div> <aside class="page-sidebar"> <div class="page-side-toolbar"><div class="option-box-toc-fixed"><div class="toc-container-sidebar"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="max-height:650px"><div style="font-weight:bold;text-align:center;">SA实战 ·《SpringCloud Alibaba实战》第19章-消息服务：项目整合RocketMQ</div> <hr> <div class="toc-box"><ul class="toc-sidebar-links"><li><a href="/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html#本章总览" class="toc-sidebar-link">本章总览</a><ul class="toc-sidebar-sub-headers"></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html#rocketmq环境准备" class="toc-sidebar-link">RocketMQ环境准备</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html#源码编译安装rocketmq" class="toc-sidebar-link">源码编译安装RocketMQ</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html#测试rocketmq环境" class="toc-sidebar-link">测试RocketMQ环境</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html#源码编译rocketmq控制台" class="toc-sidebar-link">源码编译RocketMQ控制台</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html#验证rocketmq控制台" class="toc-sidebar-link">验证RocketMQ控制台</a></li></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html#编码测试rocketmq" class="toc-sidebar-link">编码测试RocketMQ</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html#导入rocketmq依赖" class="toc-sidebar-link">导入RocketMQ依赖</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html#编写生产者代码" class="toc-sidebar-link">编写生产者代码</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html#编写消费者代码" class="toc-sidebar-link">编写消费者代码</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html#测试消息的生产与消费" class="toc-sidebar-link">测试消息的生产与消费</a></li></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html#项目整合rocketmq" class="toc-sidebar-link">项目整合RocketMQ</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html#用户微服务整合rocketmq" class="toc-sidebar-link">用户微服务整合RocketMQ</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html#订单微服务整合rocketmq" class="toc-sidebar-link">订单微服务整合RocketMQ</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html#测试项目整合的rocketmq" class="toc-sidebar-link">测试项目整合的RocketMQ</a></li></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html#关于星球" class="toc-sidebar-link">关于星球</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html#星球提供的服务" class="toc-sidebar-link">星球提供的服务</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html#星球门票价格" class="toc-sidebar-link">星球门票价格</a></li></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html#写在最后" class="toc-sidebar-link">写在最后</a><ul class="toc-sidebar-sub-headers"></ul></li></ul></div></div></div></div></div> <div class="option-box-toc-over"><img src="/images/system/toc.png" class="nozoom"> <span class="show-txt">目录</span> <div class="toc-container"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="max-height:550px"><div style="font-weight:bold;text-align:center;">SA实战 ·《SpringCloud Alibaba实战》第19章-消息服务：项目整合RocketMQ</div> <hr> <div class="toc-box"><ul class="toc-sidebar-links"><li><a href="/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html#本章总览" class="toc-sidebar-link">本章总览</a><ul class="toc-sidebar-sub-headers"></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html#rocketmq环境准备" class="toc-sidebar-link">RocketMQ环境准备</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html#源码编译安装rocketmq" class="toc-sidebar-link">源码编译安装RocketMQ</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html#测试rocketmq环境" class="toc-sidebar-link">测试RocketMQ环境</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html#源码编译rocketmq控制台" class="toc-sidebar-link">源码编译RocketMQ控制台</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html#验证rocketmq控制台" class="toc-sidebar-link">验证RocketMQ控制台</a></li></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html#编码测试rocketmq" class="toc-sidebar-link">编码测试RocketMQ</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html#导入rocketmq依赖" class="toc-sidebar-link">导入RocketMQ依赖</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html#编写生产者代码" class="toc-sidebar-link">编写生产者代码</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html#编写消费者代码" class="toc-sidebar-link">编写消费者代码</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html#测试消息的生产与消费" class="toc-sidebar-link">测试消息的生产与消费</a></li></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html#项目整合rocketmq" class="toc-sidebar-link">项目整合RocketMQ</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html#用户微服务整合rocketmq" class="toc-sidebar-link">用户微服务整合RocketMQ</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html#订单微服务整合rocketmq" class="toc-sidebar-link">订单微服务整合RocketMQ</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html#测试项目整合的rocketmq" class="toc-sidebar-link">测试项目整合的RocketMQ</a></li></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html#关于星球" class="toc-sidebar-link">关于星球</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html#星球提供的服务" class="toc-sidebar-link">星球提供的服务</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html#星球门票价格" class="toc-sidebar-link">星球门票价格</a></li></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html#写在最后" class="toc-sidebar-link">写在最后</a><ul class="toc-sidebar-sub-headers"></ul></li></ul></div></div></div></div></div> <div class="option-box"><img src="/images/system/wechat.png" class="nozoom"> <span class="show-txt">手机看</span> <div class="toc-container"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="text-align:center"><span style="font-size:0.9rem">微信扫一扫</span> <img height="180px" src="https://api.qrserver.com/v1/create-qr-code/?data=https://binghe001.github.io/md/microservices/springcloudalibaba/2022-05-18-SA%E5%AE%9E%E6%88%98-%E7%AC%AC19%E7%AB%A0-%E6%B6%88%E6%81%AF%E6%9C%8D%E5%8A%A1-%E9%A1%B9%E7%9B%AE%E6%95%B4%E5%90%88RocketMQ.html" style="margin:10px;">
                可以<b>手机看</b>或分享至<b>朋友圈</b></div></div></div></div> <div class="option-box"><img src="/images/system/toggle.png" width="30px" class="nozoom"> <span class="show-txt">左栏</span></div> <div class="option-box"><img src="/images/system/xingqiu.png" width="25px" class="nozoom"> <span class="show-txt">星球</span> <div class="toc-container"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="text-align:center"><span style="font-size:0.8rem;font-weight:bold;">实战项目<span style="font-size:8px;color:red;">「SpringCloud Alibaba实战项目」</span>、专属电子书、问题解答、简历指导、技术分享、晋升指导、视频课程</span> <img height="180px" src="/images/personal/xingqiu.png" style="margin:10px;"> <b>知识星球</b>：冰河技术
            </div></div></div></div> <div class="option-box"><img src="/images/system/wexin4.png" width="25px" class="nozoom"> <span class="show-txt">读者群</span> <div class="toc-container"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="text-align:center"><span style="font-size:0.8rem;font-weight:bold;">添加冰河微信<span style="color:red;">(hacker_binghe)</span>进冰河技术学习交流圈「无任何套路」</span> <img src="/images/personal/hacker_binghe.jpg" height="180px" style="margin:10px;">
                PS：添加时请备注<b>读者加群</b>，谢谢！
              </div></div></div></div> <div class="option-box"><img src="/images/system/download-2.png" width="25px" class="nozoom"> <span class="show-txt">下资料</span> <div class="toc-container"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="text-align:center"><span style="font-size:0.8rem;font-weight:bold;">扫描公众号，回复<span style="color:red;">“1024”</span>下载<span style="color:red;">100GB+</span>学习技术资料、PDF书籍、实战项目、简历模板等「无任何套路」</span> <img src="/images/personal/qrcode.png" height="180px" style="margin:10px;"> <b>公众号:</b> 冰河技术
              </div></div></div></div> <div class="option-box"><img src="/images/system/heart-1.png" width="25px" class="nozoom"> <span class="show-txt">赞赏我</span> <div class="toc-container"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="text-align:center"><span style="font-size:0.8rem;font-weight:bold;">鼓励/支持/赞赏我</span> <img height="180px" src="/images/personal/encourage-head.png" style="margin:5px;"> <br>1. 不靠它生存但仍希望得到你的鼓励；
                <br>2. 时刻警醒自己保持技术人的初心；
              </div></div></div></div> <div title="SA实战 ·《SpringCloud Alibaba实战》第18章-消息服务：MQ使用场景与选型对比" class="option-box" style="padding-left:2px;text-align:center;"><a href="/md/microservices/springcloudalibaba/2022-05-17-SA实战-第18章-消息服务-MQ使用场景与选型对比.html"><img src="/images/system/pre2.png" width="30px" class="nozoom"> <span class="show-txt">上一篇</span></a></div> <div title="SA实战 ·《SpringCloud Alibaba实战》第20章-消息服务：RocketMQ核心技术" class="option-box" style="padding-left:2px;text-align:center;"><a href="/md/microservices/springcloudalibaba/2022-05-20-SA实战-第20章-消息服务-RocketMQ核心技术.html"><img src="/images/system/next2.png" width="30px" class="nozoom"> <span class="show-txt">下一篇</span></a></div></div>  <!----> </aside></div><div class="global-ui"><div class="read-more-wrap" style="display:none;position:absolute;bottom:0px;z-index:9999;width:100%;margin-top:-100px;font-family:PingFangSC-Regular, sans-serif;"><div id="read-more-mask" style="position: relative; height: 200px; background: -webkit-gradient(linear, 0 0%, 0 100%, from(rgba(255, 255, 255, 0)), to(rgb(255, 255, 255)));"></div> <a id="read-more-btn" target="_self" style="position: absolute; left: 50%; top: 70%; bottom: 30px; transform: translate(-50%, -50%); width: 160px; height: 36px; line-height: 36px; font-size: 15px; text-align: center; border: 1px solid rgb(222, 104, 109); color: rgb(222, 104, 109); background: rgb(255, 255, 255); cursor: pointer; border-radius: 6px;">阅读全文</a> <div id="btw-modal-wrap" style="display: none;"><div id="btw-mask" style="position: fixed; top: 0px; right: 0px; bottom: 0px; left: 0px; opacity: 0.7; z-index: 999; background: rgb(0, 0, 0);"></div> <div id="btw-modal" style="position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 300px; text-align: center; font-size: 13px; background: rgb(255, 255, 255); border-radius: 10px; z-index: 9999; font-family: PingFangSC-Regular, sans-serif;"><span id="btw-modal-close-btn" style="position: absolute; top: 5px; right: 15px; line-height: 34px; font-size: 34px; cursor: pointer; opacity: 0.2; z-index: 9999; color: rgb(0, 0, 0); background: none; border: none; outline: none;">×</span> <p id="btw-modal-header" style="margin-top: 40px; line-height: 1.8; font-size: 13px;">
                扫码或搜索：<span style="color: #E9405A; font-weight: bold;">冰河技术</span> <br>发送：<span id="fustack-token" class="token" style="color: #e9415a; font-weight: bold; font-size: 17px; margin-bottom: 45px;">290992</span> <br>即可<span style="color: #e9415a; font-weight: bold;">立即永久</span>解锁本站全部文章</p> <img src="/images/personal/qrcode.png" style="width: 180px; margin-top: 10px; margin-bottom: 30px; border: 8px solid rgb(230, 230, 230);"></div></div></div><div class="pay-read-more-wrap" style="display:none;position:absolute;bottom:0px;z-index:9999;width:100%;margin-top:-100px;font-family:PingFangSC-Regular, sans-serif;"><div id="pay-read-more-mask" style="position: relative; height: 200px; background: -webkit-gradient(linear, 0 0%, 0 100%, from(rgba(255, 255, 255, 0)), to(rgb(255, 255, 255)));"></div> <a id="pay-read-more-btn" target="_blank" style="position: absolute; left: 50%; top: 70%; bottom: 30px; transform: translate(-50%, -50%); width: 160px; height: 36px; line-height: 36px; font-size: 15px; text-align: center; border: 1px solid rgb(222, 104, 109); color: rgb(222, 104, 109); background: rgb(255, 255, 255); cursor: pointer; border-radius: 6px;">付费阅读</a></div></div></div>
    <script src="/assets/js/cg-styles.js?v=1653305936337" defer></script><script src="/assets/js/cg-4.js?v=1653305936337" defer></script><script src="/assets/js/cg-3.js?v=1653305936337" defer></script><script src="/assets/js/cg-307.js?v=1653305936337" defer></script><script src="/assets/js/cg-5.js?v=1653305936337" defer></script><script src="/assets/js/cg-6.js?v=1653305936337" defer></script><script src="/assets/js/cg-app.js?v=1653305936337" defer></script>
  </body>
</html>
